package com.shangxia.monomer.study.designPatterns.structuralType.decorator;

import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: monomer
 * @ClassName: DecoratorDemo
 * @Time: 2021/7/23
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class DecoratorDemo {
    public static void main(String[] args) {
        Beverage beverage = new HouseBlend();
        beverage = new Mocha(beverage);
        beverage = new Milk(beverage);
        System.out.println(beverage.cost());
    }

}


interface Beverage {
    double cost();
}

class DarkRoast implements Beverage {
    @Override
    public double cost() {
        return 1;
    }
}

class HouseBlend implements Beverage {
    @Override
    public double cost() {
        return 1;
    }
}

abstract class CondimentDecorator implements Beverage {
    protected Beverage beverage;
}

class Milk extends CondimentDecorator {

    public Milk(Beverage beverage) {
        this.beverage = beverage;
    }

    @Override
    public double cost() {
        return 1 + beverage.cost();
    }
}

class Mocha extends CondimentDecorator {

    public Mocha(Beverage beverage) {
        this.beverage = beverage;
    }

    @Override
    public double cost() {
        return 1 + beverage.cost();
    }
}
